package cd.gok;

import java.io.*;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Calendar;


public class homework4 {
    //1.大数运算
    private static void 大数运算() {
        BigDecimal a1=new BigDecimal("4444444.4444");
        BigDecimal a2=new BigDecimal("3.333333");
        BigDecimal result=a1.divide(a2,2, RoundingMode.HALF_UP);
        System.out.println("结果为："+result.toString());
        System.out.println("-----------------------------------");
    }
    //2.生日
    private static void 生日() {
        Calendar calendar = Calendar.getInstance();
        calendar.set(2000,07,05);
        int date = calendar.get(Calendar.DAY_OF_WEEK);
        System.out.println("生日这天是周"+date);
        calendar.add(Calendar.DAY_OF_YEAR,-11);
        int day=calendar.get(Calendar.DAY_OF_YEAR);
        System.out.println("前一周的周四是该年第："+day+"天");
        System.out.println("-----------------------------------");

    }
    //3.文件递归
    public static void showDir(File file) {
        File file1[] = file.listFiles();
        for (File file2 : file1) {
            if (file2.isFile()) {
                String s= file2.toString();
                boolean b=s.endsWith(".java");
                if(b){
                System.out.println("文件绝对路径" + file2.getAbsolutePath());}
            } else if (file.isDirectory()) {
                showDir(file2);
            }
        }
    }
    //4.文件拷贝
    public static void creat()throws IOException{
        File file1 = new File("D:\\HelloWorld.txt");
        file1.mkdir();
        System.out.println(file1.exists());
        System.out.println("文件存在");
        System.out.println("是否为目录:" + file1.isDirectory());
        System.out.println("是否为文件:" + file1.isFile());
        System.out.println("-----------------------------------");
        File file2 = new File("D:\\IOTest");
        file2.mkdir();
        System.out.println(file2.exists());
        System.out.println("文件存在");
        System.out.println("是否为目录:" + file2.isDirectory());
        System.out.println("是否为文件:" + file2.isFile());
        System.out.println("-----------------------------------");
        //字符缓冲流
        BufferedReader bfr=new BufferedReader(new FileReader("D:\\HelloWorld.txt"));
        BufferedWriter bfw=new BufferedWriter(new FileWriter("D:\\IOTest\\a.txt"));
        System.out.println("数据拷贝成功");
        System.out.println("-----------------------------------");
        //缓冲读取的时候，可以读取行
        String line="";
        while ((line=bfr.readLine())!=null){
            bfw.write(line);
            bfw.newLine();//换行
        }
        bfw.close();
        bfr.close();


    }
    //5.转换编码
    private static void 转换编码() throws IOException{
        OutputStreamWriter osw=new OutputStreamWriter(new FileOutputStream("D:\\IOTest\\b.txt"),"GBK");
        osw.write(97);
        osw.write("你好啊");
        System.out.println("编码转换完成");
        osw.close();
    }

    public static void main(String[] args)throws IOException {
        大数运算();
        生日();
        File file=new File("D:\\idea\\workspace\\homework\\day4\\src");
        showDir(file);
        System.out.println("-----------------------------------");
        creat();
        转换编码();



    }




}
